package org.logic.fuzzysets;

import java.util.List;

import org.logic.fuzzy.FuzzyMath;
import org.logic.membershipFunctions.AMembershipFunction;

public abstract class AFuzzySet {

	String subject;
	AFuzzySet qualifier;
	AMembershipFunction membershipFunction;
	List<Double> universe;

	public String getSubject() {
		return subject;
	}

	public void setSubject(String subject) {
		this.subject = subject;
	}

	public List<Double> getUniverse() {
		return universe;
	}

	public void setUniverse(List<Double> universe) {
		this.universe = universe;
	}
	
	public AFuzzySet getQualifier() {
		return qualifier;
	}

	public void setQualifier(AFuzzySet qualifier) {
		this.qualifier = qualifier;
	}

	public AMembershipFunction getMembershipFunction() {
		return membershipFunction;
	}

	public void setMembershipFunction(AMembershipFunction membFunction) {
		this.membershipFunction = membFunction;
	}

	public Double getCardinalValue() {

		if (qualifier == null || subject!=null) {
			Double cardinalValue = 0.0;

			for (Double record : universe) {
				cardinalValue += membershipFunction.getMembershipDegree(record);
			}
			return cardinalValue;
		}
		else{
			// przypadek z kwalifikatorem
			
			Double cardinalValue = 0.0;

			for (int i = 0; i< universe.size(); i++) {
				cardinalValue += FuzzyMath.min(membershipFunction.getMembershipDegree(universe.get(i)),
						qualifier.getMembershipFunction().getMembershipDegree(qualifier.universe.get(i)));
			}
			return cardinalValue;
		}
	}

	abstract public String getLabel();

}